package com.small.os.minio.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.small.os.minio.entity.AqShare;
import com.small.os.minio.entity.AqShareInfo;
import com.small.os.minio.mapper.AqShareMapper;
import com.small.os.minio.service.IAqShareInfoService;
import com.small.os.minio.service.IAqShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 文件分享 服务实现类
 * </p>
 *
 * @author wangguochao
 * @since 2020-10-20
 */
@Service

public class AqShareServiceImpl extends ServiceImpl<AqShareMapper, AqShare> implements IAqShareService {
    @Autowired
    private IAqShareInfoService iAqShareInfoService;
    @Resource
    private AqShareMapper aqShareMapper;

    @Override
    public AqShare createShare(AqShare param) {
        List<AqShareInfo> list = param.getAqShareInfoList();
        this.save(param);
        for (AqShareInfo aqShareInfo : list) {
            aqShareInfo.setAqShareId(param.getId());
        }
        iAqShareInfoService.saveBatch(list);
        return param;
    }

    @Override
    public List<AqShareInfo> findShareInfoByShareId(String shareId) {
        LambdaQueryWrapper<AqShareInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AqShareInfo::getAqShareId, shareId);
        return iAqShareInfoService.list(wrapper);
    }

    @Override
    public IPage<AqShare> findPage(Page<AqShare> page, QueryWrapper<AqShare> wrapper) {
        return aqShareMapper.findPage(page, wrapper);
    }


}
